package com.alex.ioc.scope;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Application {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("scope.xml");

        Car car1_1 = (Car) ctx.getBean("car1");
        Car car1_2 = (Car) ctx.getBean("car1");

        // 默认的作用域是单例模式 singleton, 容器初始化时就创建实例
        System.out.println(car1_1 == car1_2);

        // car2的作用域声明为prototype, 容器初始化时不创建实例, 每次getBean时spring都会返回新创建的bean对象引用
        Car car2_1 = (Car) ctx.getBean("car2");
        Car car2_2 = (Car) ctx.getBean("car2");
        System.out.println(car2_1 == car2_2);
    }
}
